package com.aaa.cts.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.cts.entity.DictType;
import com.aaa.cts.service.DictTypeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 字典类型表(DictType)表控制层
 *
 * @author makejava
 * @since 2020-12-14 20:36:50
 */
@RestController
@RequestMapping("dictType")
public class DictTypeController {
    /**
     * 服务对象
     */
    @Resource
    private DictTypeService dictTypeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public DictType selectOne(Integer id) {
        return this.dictTypeService.queryById(id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param dictType 实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody DictType dictType) {
        return this.dictTypeService.queryAll(pageNo, pageSize, dictType);
    }

    /**
     * 根据ID删除
     *
     * @param dictId id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer dictId) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.dictTypeService.deleteById(dictId));
    }

    /**
     * 更新
     *
     * @param @param dictType 实例对象
     * @return Result
     */
    @PostMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody DictType dictType) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.dictTypeService.update(dictType));
    }

    /**
     * 添加
     *
     * @param @param dictType 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody DictType dictType) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.dictTypeService.insert(dictType));
    }
}